<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button>点我</button>
    <script>
        // setTimeout(()=>{
        //     console.log(1);
        //     setTimeout(()=>{
        //         console.log(2);
        //         setTimeout(()=>{
        //             console.log(3);
        //             setTimeout(()=>{
        //                 console.log(4);
        //             },4000);                    
        //         },3000);
        //     },2000);
        // },1000);

        function f(n){
            return new Promise( (resolve,reject)=>{
                    setTimeout(()=>{
                        console.log(new Date(),n);
                        resolve(n);
                    },1000*n);
                });
        }
        console.log(new Date(),0);
        // const p1 = f(1)
        // const p2 = p1.then((n)=>f(n+1))
        // const p3 = p2.then((n)=>f(n+1))
        // const p4 = p3.then((n)=>f(n+1))

        f(1).then((n)=>f(n+1)).then((n)=>f(n+1)).then((n)=>f(n+1))


 



    </script>
</body>
</html>